package com.hiwhitley.leetcode.easy;

/**
 * Created by hiwhitley on 17-2-13.
 */
public class NextGreaterElement_503 {
    public int[] nextGreaterElements(int[] nums) {
        if(nums == null || nums.length == 0) return new int[0];
        int n = nums.length;
        int[] result = new int[n];
        for(int i = 0; i < n; ++i){
            int j = (i + 1) % n;
            for(; j != n && j != i; ){
                if(nums[j] > nums[i]) break;
                j = (j + 1) % n;
            }
            if(j == i) result[i] = -1;
            else result[i] = nums[j];
        }
        return result;
    }
}
